package com.pp.controller;


import com.alibaba.fastjson.JSONObject;
import com.pp.bean.GovStoryInfoImage;
import com.pp.service.GovStoryInfoImageService;
import com.pp.util.Respons.ResponseUtil;
import com.pp.util.upload.UploadFile;
import com.sun.org.apache.regexp.internal.RE;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javafx.scene.chart.ValueAxis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;
import org.springframework.web.multipart.MultipartFile;

import java.io.FileNotFoundException;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 品牌故事详情富文本的图片 前端控制器
 * </p>
 *
 * @author 冯政尚
 * @since 2019-04-03
 */
@Controller
@RequestMapping("/govStoryInfoImage")
@Api(value = "品牌故事详情富文本的图片Controller", tags = {"品牌故事详情富文本的图片类型类"})
public class GovStoryInfoImageController {

    @Autowired
    GovStoryInfoImageService govStoryInfoImageService;


    /*@RequestMapping(value = "insert",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "新增 品牌故事详情富文本的图片")
    public Map insert(@RequestBody GovStoryInfoImage govStoryInfoImage){
        if(govStoryInfoImageService.save(govStoryInfoImage)){
            return ResponseUtil.getSuccessMap();
        }
        return ResponseUtil.getExceptionMap();
    }*/


    @RequestMapping(value = "insert",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "新增 品牌故事详情富文本的图片")
    public Map insert(
                      @RequestParam("lang") Integer  lang,
                      @RequestParam("height") Integer  height,
                      @RequestParam("width") Integer  width,
                      @RequestParam("file") MultipartFile file){
        GovStoryInfoImage govStoryInfoImage = new GovStoryInfoImage();
        govStoryInfoImage.setHeight(lang);
        govStoryInfoImage.setWidth(height);
        govStoryInfoImage.setLang(width);

        try {
            String url  = UploadFile.fileUpload(file);
            govStoryInfoImage.setImageUrl(url);
            System.out.println("url:"+url);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        System.out.println("实体类:"+govStoryInfoImage);
        if(govStoryInfoImageService.save(govStoryInfoImage)){
            return ResponseUtil.getSuccessMap();
        }
        return ResponseUtil.getExceptionMap();
    }


    @RequestMapping(value = "deleteById",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "删除 品牌故事详情富文本的图片")
    public Map deleteById(@RequestBody GovStoryInfoImage govStoryInfoImage){
        if(govStoryInfoImageService.removeById(govStoryInfoImage)){
            return ResponseUtil.getSuccessMap();
        }
        return ResponseUtil.getExceptionMap();
    }

    @RequestMapping(value = "updateById",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "修改 品牌故事详情富文本的图片")
    public Map updateById(@RequestBody GovStoryInfoImage govStoryInfoImage){
        if(govStoryInfoImageService.updateById(govStoryInfoImage)){
            return ResponseUtil.getSuccessMap();
        }
        return ResponseUtil.getExceptionMap();
    }


    @RequestMapping(value = "select",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "查询 品牌故事详情富文本的图片")
    public List<GovStoryInfoImage> select(){
        return govStoryInfoImageService.list();
    }

}
